﻿Imports Global_Visas_Business_Layer
Imports System
Imports System.Data
Imports System.ComponentModel
Imports System.Collections.Generic
Partial Public Class frmAdminEditSLSLink
    Private _SLS_SLSID As Long
    Public Property SLS_SLSID() As Long
        Get
            Return _SLS_SLSID
        End Get
        Set(ByVal value As Long)
            _SLS_SLSID = value
        End Set
    End Property
    Private _SLS_SLSLinkID As Long
    Public Property SLS_SLSLinkID() As Long
        Get
            Return _SLS_SLSLinkID
        End Get
        Set(ByVal value As Long)
            _SLS_SLSLinkID = value
        End Set
    End Property

    Private _SLS_LPID As Long
    Public Property SLS_LPID() As Long
        Get
            Return _SLS_LPID
        End Get
        Set(ByVal value As Long)
            _SLS_LPID = value
        End Set
    End Property

    Private _Frm_Start As Integer
    Public Property Frm_Start() As Integer
        Get
            Return _Frm_Start
        End Get
        Set(ByVal value As Integer)
            _Frm_Start = value
        End Set
    End Property

    Private _Frm_End As Integer
    Public Property Frm_End() As Integer
        Get
            Return _Frm_End
        End Get
        Set(ByVal value As Integer)
            _Frm_End = value
        End Set
    End Property

    Private _Frm_Client As Integer
    Public Property Frm_Client() As Integer
        Get
            Return _Frm_Client
        End Get
        Set(ByVal value As Integer)
            _Frm_Client = value
        End Set
    End Property

    Private _LetterPackText As String
    Public Property SLS_LetterPackText() As String
        Get
            Return _LetterPackText
        End Get
        Set(ByVal value As String)
            _LetterPackText = value
        End Set
    End Property
    Private _SLS_List_SLS As String
    Public Property SLS_List_SLS() As String
        Get
            Return _SLS_List_SLS
        End Get
        Set(ByVal value As String)
            _SLS_List_SLS = value
        End Set
    End Property


    Private Sub Btn_Cancel_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Btn_Cancel.Click
        Me.Close()
    End Sub

    Private Sub Btn_Save_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Btn_Save.Click
        Try

            Dim StrSQL As String, StrMess As String
            Dim LPID As Long, SLSID As Long, SLSLinkID As Long
            'LPID = Form_FMA_SLS.List_Letterpacks.Column(1)
            'SLSID = Form_FMA_SLS.List_SLS
            'SLSLinkID = Form_FMA_SLS.List_Letterpacks
            LPID = SLS_LPID
            SLSID = SLS_SLSID
            SLSLinkID = SLS_SLSLinkID

            'Validations
            If Me.Frm_Start = 3 And Me.Combo_Start.SelectedIndex = -1 Then
                Call MsgBox("Please select a custom start stage or change to another option")
                Me.Combo_Start.Focus()
                Exit Sub
            End If

            If Me.Frm_End = 4 And Me.Combo_End.SelectedIndex = -1 Then
                Call MsgBox("Please select a custom end stage or change to another option")
                Me.Combo_End.Focus()
                Exit Sub
            End If

            If Me.Frm_Start = 3 And Me.Frm_End = 3 And Me.Combo_Start.SelectedValue > Me.Combo_End.SelectedValue Then
                Call MsgBox("End Stage cannot be before Start Stage", , "Error")
                Exit Sub
            End If

            'Build Sys Event Message
            StrMess = "Scope for Letterpack no. " & LPID & " (" & SLS_LetterPackText & ") in Stock Letter Set " & SLSID & " (" & Me.SLS_List_SLS & ") set as follows."
            StrMess = StrMess & vbCrLf & vbCrLf
            StrMess = StrMess & "Start Stage :"
            Select Case Me.Frm_Start

                Case 1
                    StrMess = StrMess & " New Lead"

                Case 2
                    StrMess = StrMess & " Sold"

                Case 3
                    StrMess = StrMess & " Custom, " & Me.Combo_Start.Text & " (" & Me.Combo_Start.SelectedValue & ")"

            End Select

            StrMess = StrMess & vbCrLf & "End Stage   :"
            Select Case Me.Frm_End

                Case 1
                    StrMess = StrMess & " Sold"

                Case 2
                    StrMess = StrMess & " Closed"

                Case 4
                    StrMess = StrMess & " Custom, " & Me.Combo_End.Text & " (" & Me.Combo_End.SelectedValue & ")"

                Case 3
                    StrMess = StrMess & " After Closed"

            End Select

            StrMess = StrMess & vbCrLf & "Client Type :"
            Select Case Me.Frm_Client

                Case 0
                    StrMess = StrMess & " All"

                Case 1
                    StrMess = StrMess & " Private"

                Case 2
                    StrMess = StrMess & " Corporate"

            End Select

            'Build SQL
            StrSQL = "Update I_SL_SLSLink Set SLSLink_StageStart =  "

            Select Case Me.Frm_Start

                Case 1
                    StrSQL = StrSQL & "0"

                Case 2
                    StrSQL = StrSQL & "100"

                Case 3
                    StrSQL = StrSQL & Me.Combo_Start.SelectedValue

            End Select

            StrSQL = StrSQL & ", SLSLink_StageEnd = "

            Select Case Me.Frm_End

                Case 1
                    StrSQL = StrSQL & "99"

                Case 2
                    StrSQL = StrSQL & "999"
                
                Case 3
                    StrSQL = StrSQL & "0"

                Case 4
                    StrSQL = StrSQL & Me.Combo_End.SelectedValue

            End Select

            StrSQL = StrSQL & ", SLSLink_CustomerType = " & Me.Frm_Client

            StrSQL = StrSQL & " WHERE SLSLink_ID = " & SLSLinkID

            'Execute
            If CommonDataFunctions.ExecuteSQL(StrSQL) = False Then Exit Sub

            Call (New TasksEvents).GblFunc_Add_SysEvent("Admin (SL)", StrMess)

            'Form_FMA_SLS.List_Letterpacks.Requery()

            'DoCmd.Close(acForm, "FMA_EditSLSLink")
            Me.Close()

        Catch ex As Exception
            CommonFuncs.ErrorHandler(ex, "frmAdminEditSLSLink-Btn_Save_Click")
        End Try
    End Sub

    Private Sub frmAdminEditSLSLink_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        GeneralTasks.ChangeTheme(Me)
        GeneralTasks.EnumerateandFill(Me.LogicalChildren)
        SetTheRadioButtons()
    End Sub
    Private Sub SetTheRadioButtons()
        Select Case Me.Frm_Start
            Case 1
                Me.Option4.IsChecked = True
                Me.Combo_Start.IsEnabled = False
            Case 2
                Me.Option6.IsChecked = True
                Me.Combo_Start.IsEnabled = False
            Case 3
                Me.Option8.IsChecked = True
                Me.Combo_Start.IsEnabled = True
        End Select
        Select Case Me.Frm_End
            Case 1
                Me.Option13.IsChecked = True
                Me.Combo_End.IsEnabled = False
            Case 2
                Me.Option15.IsChecked = True
                Me.Combo_End.IsEnabled = False
            Case 3
                Me.Option32.IsChecked = True
                Me.Combo_End.IsEnabled = False
            Case 4
                Me.Option17.IsChecked = True
                Me.Combo_End.IsEnabled = True
        End Select
        Select Case Me.Frm_Client
            Case 0
                Me.Option22.IsChecked = True
            Case 1
                Me.Option24.IsChecked = True
            Case 2
                Me.Option26.IsChecked = True
        End Select
    End Sub

    Private Sub Option4_Checked(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Option4.Checked
        Me.Frm_Start = 1
        Me.Combo_Start.SelectedIndex = -1
        Me.Combo_Start.IsEnabled = False
    End Sub

    Private Sub Option6_Checked(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Option6.Checked
        Me.Frm_Start = 2
        Me.Combo_Start.SelectedIndex = -1
        Me.Combo_Start.IsEnabled = False
    End Sub

    Private Sub Option8_Checked(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Option8.Checked
        Me.Frm_Start = 3
        Me.Combo_Start.IsEnabled = True
    End Sub

    Private Sub Option13_Checked(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Option13.Checked
        Me.Frm_End = 1
        Me.Combo_End.SelectedIndex = -1
        Me.Combo_End.IsEnabled = False
    End Sub

    Private Sub Option15_Checked(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Option15.Checked
        Me.Frm_End = 2
        Me.Combo_End.SelectedIndex = -1
        Me.Combo_End.IsEnabled = False
    End Sub

    Private Sub Option32_Checked(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Option32.Checked
        Me.Frm_End = 3
        Me.Combo_End.SelectedIndex = -1
        Me.Combo_End.IsEnabled = False
    End Sub

    Private Sub Option17_Checked(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Option17.Checked
        Me.Frm_End = 4
        Me.Combo_End.IsEnabled = True
    End Sub

    Private Sub Option22_Checked(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Option22.Checked
        Me.Frm_Client = 0
    End Sub

    Private Sub Option24_Checked(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Option24.Checked
        Me.Frm_Client = 1
    End Sub

    Private Sub Option26_Checked(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Option26.Checked
        Me.Frm_Client = 2
    End Sub
End Class
